let ajax = new class{
	// 初始化
	constructor(){

		this.xmr = new XMLHttpRequest();

		this.xmr.onreadystatechange = () =>{

			if(this.xmr.readyState == 4 && this.xmr.status == 200){

				let response = this.xmr.responseText;

				if(this.type == "json"){

					response = JSON.parse(response);
				}
				this.callback(response);
			}
		}
	}

	// get方法请求数据
	get(url, ginseng, callback, type = "text"){

		let data = this.parseParameters(ginseng);

		if(data.length > 0){

			url += "?" +data;
		}

		this.type      =  type;
		this.callback  =  callback;

		this.xmr.open("GET", url, true);
		this.xmr.send();
	}

	// post方法请求数据
	post(url, ginseng, callback, type = "text"){

		let data = this.parseParameters(ginseng);

		this.type      =  type;
		this.callback  =  callback;

		this.xmr.open("POST", url, true);
		this.xmr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		this.xmr.send(data);
	}

	// 字符串的拼接
	parseParameters(parameters){

		let strbum = "";

		for(let key in parameters){

			let str = key + "=" +parameters[key];
			strbum += str +"&";
		}

		return strbum.substring(0,strbum.length - 1);
	}
}